<template>
  <views class="terrace_adminstrators">
    <viewTitle :title="'管理员列表'" :border="false"></viewTitle>
    <el-form ref="form" label-width="auto" :inline="true">
      <div class="user_name">
        <el-form-item label="管理员名称:">
          <el-input
            style="width:200px"
            type="text"
            clearable
            placeholder="管理员名称"
            v-model="user_name"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="query()" icon="el-icon-search">查询</el-button>
          <el-button @click="reset()" icon="el-icon-refresh">重置</el-button>
          <el-button type="danger" @click="add()" v-show="isAdd">新增</el-button>
        </el-form-item>
      </div>
    </el-form>
    <div class="table_data">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="is_admins" label="是否是管理员" width="150"></el-table-column>
        <el-table-column prop="status_name" label="状态" width="120"></el-table-column>
        <el-table-column prop="user_real_name" label="真实姓名" width="120"></el-table-column>
        <el-table-column prop="user_mobile" label="电话"></el-table-column>
        <el-table-column prop="user_name" label="管理员名称"></el-table-column>
        <el-table-column prop="email" label="邮箱"></el-table-column>
        <el-table-column prop="created_datetime" label="创建时间" width="180"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="300"
          v-if="isLook && isEdit && isDelete"
        >
          <template slot-scope="scope">
            <el-button @click="look(scope.row)" v-show="isLook">查看</el-button>
            <el-button type="primary" @click="edit(scope.row)" v-show="isEdit">编辑</el-button>
            <el-button type="info" @click="deleted(scope.row)" v-show="isDelete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paging flex flexR">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="handleSizeChange($event)"
          @current-change="changePage($event)"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>





<script>
export default {
  name: "TerraceAdministrators",
  data() {
    return {
      user_name: "", //搜索管理员名称
      tableData: [], //表格数据
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    };
  },
  mounted() {
    //获取列表数据
    this.query();
  },
  computed: {
    //实时计算要传输的编辑参数
    post_data() {
      let data = {};
      data.user_name = this.user_name;
      data.pagination = this.pagination;
      console.log("data", data);
      return data;
    },
    isAdd(){      //判断是否具有 “新增” 按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].add ? 1 : 0;
    },
    isEdit(){     //判断是否具有  “编辑”  按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].edit ? 1 : 0;
    },
    isLook(){      //判断是否具有 “查看” 按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].look ? 1 : 0;
    },
    isDelete(){     //判断是否具有  “删除”  按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].delete ? 1 : 0;
    }
  },
  methods: {
    query() {
      //获取列表数据
      this.$raxios
        .post(this.$mapapi.adminUserList, { data: this.post_data })
        .then(res => {
          if (res.code != 200 && res.code != 501) {
            this.tableData = [];
            this.pagination = {
              page_start: 0,
              current_page: 0,
              page_count: 0,
              page_size: 10,
              total_count: 0
            };
            return Promise.reject(res.msg);
          }
          this.tableData = res.data.list;
          this.pagination = res.data.pagination;
          console.log("user_list", res);
        })
        .catch(res => {
          this.$message.error(res);
        });
    },
    add() {
      //新增
      console.log("come here add");
      this.$toRoutePath({
        path: "/terrace_administrators/terrace_administrators_add",
        edit: true
      });
    },
    reset() {
      this.user_name = "";
    },
    handleSizeChange(page_size) {
      this.pagination.page_size = page_size;
      this.query(this.post_data);
    },
    changePage(current_page) {
      this.pagination.page_start = current_page;
      this.query(this.post_data);
    },
    look(data) {
      let admin_user_id = data.admin_user_id;
      this.$toRoutePath({
        path: "/terrace_administrators/terrace_administrators_look",
        edit: true,
        query: { admin_user_id }
      });
    },
    edit(data) {
      let admin_user_id = data.admin_user_id;
      this.$toRoutePath({
        path: "/terrace_administrators/terrace_administrators_amend",
        edit: true,
        query: { admin_user_id }
      });
    },
    deleted(data) {
      let admin_user_id = data.admin_user_id;
      this.$raxios
        .post(this.$mapapi.deleteAdminUser, { data: { admin_user_id } })
        .then(res => {
          if (res.code != 200) return Promise.reject(res.msg);
          this.$message.success(res.msg);
          this.query();
        })
        .catch(res => {
          this.$message.error(res);
        });
    }
  }
};
</script>

<style  lang="less" :scope="true" src="@/style/terrace/terrace_administrators/terrace_administrators.less">
</style>
